
from time import sleep
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By

# 1.打开浏览器
driver = webdriver.Chrome()
# driver = webdriver.Chrome() #创建浏览器对象
# 2.输入访问地址（URL）
url = r"C:\Users\ASUS\Desktop\text\UI自动化测试\UI自动化测试\drop.html"
driver.get(url)
# 放大浏览器页面
# driver.maximize_window()

# 实例化并获取ActionChains类
action = ActionChains(driver)

# 获取 源元素
source = driver.find_element_by_css_selector("#div1")
# 获取 目标元素
target = driver.find_element_by_css_selector("#div2")
sleep(3)
action.drag_and_drop(source, target).perform()
# 扩展 通过坐标偏移量执行
sleep(3)
action.drag_and_drop_by_offset(source,xoffset=300,yoffset=300).perform()